export default {
  name: "Login",
  data(){
    return {
      form:{
        username:'emp',
        password:'123456'
      },
      rules: {
        username:[
          { required: true, message: '请输入账号', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        password:[
          { required: true, message: '请输入密码', trigger: 'blur' },
        ]
      }
    }
  },
  mounted() {
    console.log(location.hash);
    /*sessionStorage.JWTHeaderName = 'JWTHeaderName'*/
  },
  methods:{
    onSubmit: function () {
      this.$refs['form'].validate( valid =>  valid ? (this.auth(),true): (console.log('error submit!!'),false) )
    },
    auth(){
      console.log('asdas',this.form)
      let formData = new FormData()
      for (let key in this.form) formData.append(key, this.form[key])
      this.$axios.post('/jwtLogin',this.form).then(res =>(
        res.code==200 && res.isok ? (
          console.log(res),
            sessionStorage.JWTHeaderName = res.data.JWTHeaderName,
            this.$router.replace("/home")
        ):res.code==401 && !res.isok? (console.log(res),this.errormsg(res.message)):''
      )).catch(error => console.log(error))
    },
    errormsg(str){
      this.$confirm(str, '提示', {
        confirmButtonText: '确定',
        type: 'warning',
        showCancelButton:false
      })
    }
  }
}
